<template>
  <div>
    <van-nav-bar
      :z-index="999"
      :fixed="true"
      left-arrow
      @click-left="onClickLeft"
      title="说明"
      :placeholder="true"
    ></van-nav-bar>
    <div class="account-for">
      <button @click="scan">扫码</button>
      <div>调用扫码方法</div>
    </div>

    <div class="account-for">
      <button @click="getGpsLocation">获取定位</button>
      <div>返回坐标</div>
    </div>

    <div class="account-for">
      <button @click="getCID">getCID</button>
      <div>获取消息推送的cid</div>
    </div>

    <div class="account-for">
      <button @click="getSHA1">getSHA1</button>
      <div>获取高德地图的sha1</div>
    </div>

    <div class="account-for">
      <button @click="goBack">goBack</button>
      <div>需要先行注册，然后返回按钮才可以用</div>
    </div>

    <div class="account-for">
      <button @click="getPicFile">getPicFile</button>
      <div>获取图片</div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";

export default {
  name: "Demo",
  data() {
    return {};
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    getGpsLocation() {
      // console.log("定位");
      let _this = this;
      let dsBridge = require("dsbridge");
      dsBridge.call("tellHtml_loc", "", function(data) {
        var jwd = "";
        try {
          jwd = JSON.parse(data);
        } catch (err) {
          _this.getGpsLocation();
        }

        Toast(
          "城市:" +
            jwd.city +
            ";地址:" +
            jwd.address +
            ";经度：" +
            jwd.lgt +
            ";纬度:" +
            jwd.lat
        );
      });
    },
    scan() {
      let dsBridge = require("dsbridge");
      dsBridge.call("scan", "", function(data) {
        Toast(data);
      });
    },
    getCID() {
      let dsBridge = require("dsbridge");
      dsBridge.call("getCID", "", function(data) {
        Toast(data);
      });
    },
    getSHA1() {
      let dsBridge = require("dsbridge");
      dsBridge.call("getSHA1", "", function(data) {
        Toast(data);
      });
    },
    goBack() {
      let dsBridge = require("dsbridge");
      dsBridge.call("goBack", "", function() {
        history.go(-1);
      });
    },
    getPicFile() {
      let dsBridge = require("dsbridge");
      dsBridge.call("getPicFile", "", function(data) {
        Toast(data);
      });
    }
  },
  created() {
    let dsBridge = require("dsbridge");
    dsBridge.call("goBack", "", function() {
      history.go(-1);
    });
  }
};
</script>
<style></style>
